package com.kepennar.application.client;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.cellview.client.ColumnSortEvent.AsyncHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.Range;
import com.google.gwt.view.client.RangeChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.event.shared.EventBus;
import com.kepennar.application.client.gaeRequest.ReloadOnAuthenticationFailure;
import com.kepennar.application.client.requests.EventProxy;
import com.kepennar.application.client.ui.EventsList;



import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Entry point for EventsList
 * 
 * 
 */
public class EventsListApp {

	private static final Logger log = Logger.getLogger(EventsList.class
			.getName());

	private final ActivityManager activityManager;
	private final EventBus eventBus;
	private final PlaceController placeController;
	private final PlaceHistoryHandler placeHistoryHandler;
	private final EventsList eventsListUi;

	public EventsListApp(ActivityManager activityManager, EventBus eventBus,
			PlaceController placeController,
			PlaceHistoryHandler placeHistoryHandler, EventsList eventsListUi) {
		this.activityManager = activityManager;
		this.eventBus = eventBus;
		this.placeController = placeController;
		this.placeHistoryHandler = placeHistoryHandler;
		this.eventsListUi = eventsListUi;
	}

	/**
	 * Start the app, and add its main widget to the given panel.
	 */
	public void run(HasWidgets root) {
		GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
			public void onUncaughtException(Throwable e) {
				log.log(Level.SEVERE, e.getMessage(), e);
			}
		});

		final CellTable<EventProxy> eventsTable = eventsListUi.getEventsTable();
		final Button addButton = eventsListUi.getAddButton();
		final Button deleteButton = eventsListUi.getDeleteButton();
		final SimplePager eventsTablePager = eventsListUi.getEventsTablePager();
		final SingleSelectionModel<EventProxy> selectionModel = eventsListUi.getSelectionModel();
		
		
	
		
		
	    
	    // Check for Authentication failures or mismatches
	    new ReloadOnAuthenticationFailure().register(eventBus);
	    
	   

	}
	
	
}
